using System.Diagnostics;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Navigation;

namespace Thunder.IrcClient
{
    /// <summary>
    /// Hyperlink control for navigating in a <see cref="RichTextBox"/>
    /// </summary>
    public class ThunderHyperlink : Hyperlink
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public ThunderHyperlink()
        {
            this.RequestNavigate += ThunderHyperlink_RequestNavigate;
        }

        /// <summary>
        /// Handles the <see cref="Hyperlink.RequestNavigate"/> event
        /// </summary>
        /// <param name="sender">The <see cref="ThunderHyperlink"/> being invoked</param>
        /// <param name="e">The event parameters containing the Uri to navigate to</param>
        private static void ThunderHyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            if (e.Uri == null || string.IsNullOrEmpty(e.Uri.AbsoluteUri) == true)
            {
                MessageBox.Show("Invalid empty Uri");
                return;
            }

            Process.Start(e.Uri.AbsoluteUri);
        }
    }
}